﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Moq;
using VideoClubGorbea.Common.Interfaces;
using VideoClubGorbea.Model;

namespace VideoClubGorbea.Tests
{
    public abstract class TestBase
    {
        public Mock<IMovieServicesProxy> MovieServicesFactoryMock { get; set; }

        internal static ControllerContext CreateControllerContext()
        {
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(x => x.Request["X-Requested-With"]).Returns("XMLHttpRequest");
            return new ControllerContext()
            {
                HttpContext = httpContext.Object
            };
        }

        public TestBase()
        {
            MovieServicesFactoryMock = new Mock<IMovieServicesProxy>();
            MovieServicesFactoryMock.Setup(x => x.GetMovieByIdAsync(2))
                  .Returns(new Task<Movie>(() =>
                  {
                      return GetTestMovie();
                  }));
            MovieServicesFactoryMock.Setup(x => x.GetLatestMoviesAsync(0))
               .Returns(new Task<List<Movie>>(() =>
               {
                   return new List<Movie>()
                    {
                        GetTestMovie(), 
                        GetTestMovie(),
                        GetTestMovie()
                    };
               }
               ));
        }

        private static Movie GetTestMovie()
        {
            return new Movie()
            {
                ForAdults = true,
                Id = 2,
                OverView = "Es una película de miedo",
                Popularity = 5,
                Price = 45.34,
                Rating = 4.5,
                Slogan = "slogan",
                Title = "Acción mutante"
            };
        }
    }
}
